
function DrawGameRiels_Idle( gameDesc ){
	for(var r = 0; r<gameDesc.nRows; r++){				
		for(var c = 0; c<gameDesc.nColumns; c++){	
			var symbol = gameDesc.simbolos[gameDesc.currentMatrix[gameDesc.nRows*c+r]];
			var imageToUse;
			if(symbol.imageIndex>=0){
				imageToUse = symbol.imageIndex;
				gameDesc.drawCanvasCtxt.drawImage( 
					gameDesc.imagesTouse[imageToUse],
					gameDesc.symbolsStartX+c*gameDesc.symbolsGridSpaceX, gameDesc.symbolsStartY+r*gameDesc.symbolsGridSpaceY, 
					gameDesc.symbolsDrawSizeX, gameDesc.symbolsDrawSizeY
				);
				
			}
		}
	}
}

function DrawGameRiels_Rotating( gameDesc ){
	for(var r = 0; r<gameDesc.nRows; r++){				
		for(var c = 0; c<gameDesc.nColumns; c++){	
			var symbol = gameDesc.simbolos[gameDesc.currentMatrix[gameDesc.nRows*c+r]];
			var imageToUse;
			if(symbol.imageIndex>=0){
				imageToUse = symbol.imageIndex;
				gameDesc.drawCanvasCtxt.drawImage( 
					gameDesc.imagesTouse[imageToUse],
					gameDesc.symbolsStartX+c*gameDesc.symbolsGridSpaceX, gameDesc.symbolsStartY+r*gameDesc.symbolsGridSpaceY, 
					gameDesc.symbolsDrawSizeX, gameDesc.symbolsDrawSizeY
				);
				
			}
		}
	}
}


function DrawGameRiels( gameDesc ){
	switch(animCtxt.state){
		case XplxnControlState.START_ANIMATION:{
			DrawGameRiels_Idle(gameDesc);
			break;
		}
		case XplxnControlState.IDLE:{
			DrawGameRiels_Idle(gameDesc);
			break;
		}
		case XplxnControlState.ROTATING:{
			DrawGameRiels_Rotating(gameDesc);
			break;
		}
	}
}

function DrawGame( gameDesc ){

	Canvas_Width = gameDesc.drawCanvas.width;
	Canvas_Height = gameDesc.drawCanvas.height;
	
	if(gameDesc.resourcesLoaded){
		//Dibujar el fondo
		gameDesc.drawCanvasCtxt.drawImage( gameDesc.imagesTouse[gameDesc.backgroundImageIndex],0,0, Canvas_Width,Canvas_Height);
		//Dibujar los controles
		for(var c = 0; c<gameDesc.controls.length; c++){
			var control = gameDesc.controls[c]
			if(control.imageIndex>=0){
				gameDesc.drawCanvasCtxt.drawImage( 
					gameDesc.imagesTouse[control.imageIndex],
					control.posX, control.posY, 
					control.width, control.height
				);
			}
		}
		//Dibujar los simbolos		
		DrawGameRiels(gameDesc);
		
	}else{
		if(gameDesc.resourcesLoadedCount==gameDesc.resourcesLoadedMaxCount){
			gameDesc.resourcesLoaded = true;
			console.log("Recursos cargados :)");
		}
		//console.log("Loading image: "+gameDesc.common.loadingImagesArray[gameDesc.index])
		gameDesc.drawCanvasCtxt.drawImage( 
			gameDesc.common.loadingImagesArray[gameDesc.index],
			0,0, 
			Canvas_Width,Canvas_Height
		);
	}



}

